<template>
  <div class="con-cah">
    <chart :options="pie" :init-options="initOptions" ref="pie" autoresize />
  </div>
</template>
<script>
import ECharts from "@/components/echarts/ECharts.vue";


export default {
  components: {
    chart: ECharts
  },
  props: {
    //[{name:"推荐量",color:"#34243",value:123},
    //{name:"阅读量",color:"#34242",value:123},
    //{name:"转发量",color:"#34243",value:123},
    //{name:"收藏量",color:"#34243",value:123}
    //]
    data: {
      type: Array,
      default: []
    },
    title: {
      type: String,
      default: ""
    }
  },
  watch: {
    data(newVal, oldVue) {
      this.init();
    }
  },
  data() {
    return {
      initOptions: {
        renderer: "canvas"
      },
      pie: {

          tooltip: {
            trigger: 'item',
            formatter: '{b}  {c} <br/> {d}%'
          },
        
          series: [
            {
              name: this.title,
              type: 'pie',
              radius: ['40%', '70%'],
              avoidLabelOverlap: false,
              label: {
               
              
                show: true,
                // position: "center",
                formatter: "{b} {d}%",
              },
              data: [
              
              ]
            }
          ],



      

     
      }
    };
  },
  methods: {
    init() {
      var list = [];
      for (var item of this.data) {
        list.push({
          value: item.value,
          name: item.name,
          radius: item.radius,
          itemStyle: {
            normal: {
              color: item.color
            }
          }
        });
      }
      this.pie.series[0].data = list;
    }
  },
  mounted() {
    this.init();
  }
};
</script>
<style  scoped>
.con-cah {
  width: 100%;
  height: 100%;
}
</style>